from wordcloud import WordCloud
import PIL.Image as  image
import numpy as np
import jieba


def transfrom_zh(text):
    word_list = jieba.cut(text)
    result = ' '.join(word_list)
    return result


filename = "ciyun.txt"
with open(filename, encoding='utf-8') as f:
    mytext = f.read()  # 读取文本
    mytext = transfrom_zh(mytext)
    mask = np.array(image.open("ciyun1.jpg"))
    wordcloud = WordCloud(
        mask=mask,
        font_path='C:\Windows\Fonts\STZHONGS.TTF'
    ).generate(mytext)

image_1 = wordcloud.to_image()
image_1.show()